package com.ljyhhh.SmartCity

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.ljyhhh.SmartCity.adapter.NewsItem
import com.ljyhhh.SmartCity.utils.MyImageView

class ItemAdapter(context: Context, resource: Int, objects: List<NewsItem>) : ArrayAdapter<NewsItem>(context,resource,objects){

    @SuppressLint("ViewHolder")
    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val new = getItem(position)

        val view = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false)
//
        val newsImage: MyImageView = view.findViewById(R.id.new_image)

        val newsTitle: TextView = view.findViewById(R.id.new_title)
        if (new != null) {


            newsImage.setImageURL(new.PicUrl)
            newsTitle.text=new.title
        }

        return view
    }
}
